<template>
  <div class="tab-bar">
    <router-link to="/" class="tab-item">
      <i class="el-icon-house"></i>
      <span>首页</span>
    </router-link>
    <router-link to="/category" class="tab-item">
      <i class="el-icon-menu"></i>
      <span>分类</span>
    </router-link>
    <router-link to="/cart" class="tab-item">
      <i class="el-icon-shopping-cart-full"></i>
      <span>购物车</span>
      <span v-if="cartCount > 0" class="cart-badge">{{ cartCount }}</span>
    </router-link>
    <router-link to="/profile" class="tab-item">
      <i class="el-icon-user"></i>
      <span>我的</span>
    </router-link>
  </div>
</template>

<script>
export default {
  computed: {
    cartCount() {
      return this.$store.getters.cartTotalCount
    }
  }
}
</script>

<style scoped>
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  height: 50px;
  background-color: #fff;
  border-top: 1px solid #eee;
  z-index: 100;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #666;
  text-decoration: none;
}

.tab-item.router-link-exact-active {
  color: #ff6600;
}

.tab-item i {
  font-size: 20px;
  margin-bottom: 2px;
}

.tab-item span {
  font-size: 12px;
}

.cart-badge {
  position: absolute;
  top: 3px;
  right: calc(25% - 25px);
  background-color: #ff4400;
  color: white;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  font-size: 10px;
}
</style>
    